package com.ccb.testcenter.servicemaping;

import java.util.LinkedList;
import java.util.List;

import org.dom4j.Document;

import com.ccb.testcenter.servicemapingconfig.DataContext;

/**
 * 
 * 类名：Request 
 * 创建人：li_dk 
 * 修改人：li_dk 
 * 创建时间：2017年1月6日 下午3:35:18 
 * 修改时间：2017年1月6日下午3:35:18 文件版本：@version 1.0.0
 *
 */
public class Request {
	//
	private boolean isconvert;
	private LinkedList<Segment> segments;
	private Document request;

	public boolean isIsconvert() {
		return isconvert;
	}

	public void setIsconvert(boolean isconvert) {
		this.isconvert = isconvert;
	}

	public LinkedList<Segment> getSegments() {
		return segments;
	}

	public void setSegments(LinkedList<Segment> segments) {
		this.segments = segments;
	}

	public Document getReqDocument() {
		return request;
	}

	public void setReqDocument(Document request) {
		this.request = request;
	}
	
	public String getRequest(DataContext context) {
		for (int i = 0; i < this.segments.size(); i++) {
			Segment segment = segments.get(i);
			List<Field> fields = segment.getaList();
			for (int j = 0; j < fields.size(); j++) {
				DirectRule rule = (DirectRule) fields.get(i).getConverter();
				rule.getConverterResult(context);
			}
			fields = segment.getdList();
			for (int j = 0; j < fields.size(); j++) {
				CustomRule rule = (CustomRule) fields.get(i).getConverter();
				rule.invoke(context);
			}
		}
		return request.asXML();
	}
}
